var path ;

$(document).ready(function(){
	
	path = $("#path").val();
	
	// 获取微信头像昵称等
	
	// 获取各种数量 现金券、物流券、待收货、已收到
	findQty();
	
	// wait receive order
//	$(".wait-receive-order").live("click",findWaitReceiveOrder);
	
	// finished order
//	$(".finished-order").live("click",findFinishedOrder);
	
	// unpaid order
//	$(".unpaid-order").live("click",findUnpaidOrder);
	
	// logistic coupon
//	$(".logisticts-coupon").live("click",findLogistictsCoupon);
	
	// cash coupon
//	$(".cash-coupon").live("click",findCashCoupon);
	
	// recepient
	$(".recepient").live("click",findRecepient);
});

function findIDCard(){
	window.location.href=path+"/user/identitycard/findAll";
}

function findAllOrder(){
	window.location.href=path+"/userorder/find/100";
}

function findRecepient(){
	window.location.href=path+"/user/address/find";
}

function findLogistictsCoupon(){
	findCoupon(1);
}

function findCashCoupon(){
	findCoupon(0);
}

function findCoupon(couponType){
	window.location.href=path+"/coupon/find/"+couponType;
}

function findWaitReceiveOrder(){
	findOrderByCondition(-1);
}

function findFinishedOrder(){
	//findFinishedOrder(7);
	findOrderByCondition(7);
}
function findUnpaidOrder(){
	findOrderByCondition(0);
}
function findOrderByCondition(status){
	window.location.href=path+"/userorder/find/"+status;
}
function addTel(telNumber){
	window.location.href = path+"/user/userTel";
}

function findQty(){
	$.ajax({
        type: "post",
        dataType: "json",
        async:true,
        url:path+"/user/findCouponOrderQty",
        success: function (result) {

        	if(result == null || result == "" || result == "undefined" || result == undefined || result == "null"){
        		return;
        	}
        	// 现金券
        	var cashCouponQty = result[0];
        	if(Number(cashCouponQty) > 0){
        		$(".cash-coupon").html('现金券<span for="num">(<span class="num">'+cashCouponQty+'</span>)</span>');
        	}
        	
        	// 物流券
        	var logistictsCouponQty = result[1];
        	if(Number(logistictsCouponQty) > 0){
        		$(".logisticts-coupon").html('物流券<span for="num">(<span class="num">'+logistictsCouponQty+'</span>)</span>');
        	}
        	
        	// 待收货
        	var waitReceiveOrder = result[2];
        	if(Number(waitReceiveOrder) >= 0){
        		$(".wait-receive-order").html('待收货<span for="num">(<span class="num">'+waitReceiveOrder+'</span>)</span>');
        	}
        	
        	// 已收到
        	var finishedOrder = result[3];
        	if(Number(finishedOrder) >= 0){
        		$(".finished-order").html('已收到<span for="num">(<span class="num">'+finishedOrder+'</span>)</span>');
        	}
        	//待支付
        	var unpaidOrder = result[4];
        	if(Number(unpaidOrder) >= 0){
        		$(".unpaid-order").html('待支付<span for="num">(<span class="num">'+unpaidOrder+'</span>)</span>');
        	}
        }
	 });
}